package cn.xfdzx.android.apps.shop.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.SearchShopsAdapter;;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.view.CheckableTextView;

import static android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT;

/**
 * 废弃界面
 */
public class SearchResultActivity extends BaseMvpActivity {

    @BindView(R.id.tv_search_result_comprehensive_sequencing)
    CheckableTextView tvSearchResultComprehensiveSequencing;//综合排序
    @BindView(R.id.tv_search_result_sales)
    CheckableTextView tvSearchResultSales;//销量
    @BindView(R.id.tv_search_result_distance)
    CheckableTextView tvSearchResultDistance;//距离
    @BindView(R.id.tv_search_result_breaks_the_freight)
    CheckableTextView tvSearchResultBreaksTheFreight;//减免运费
    @BindView(R.id.tv_search_result_high_quality_stores)
    CheckableTextView tvSearchResultHighQualityStores;//优质门店
    @BindView(R.id.tv_search_result_members_red_envelope)
    CheckableTextView tvSearchResultMembersRedEnvelope;//会员红包
    @BindView(R.id.tv_search_result_comments_high_marks)
    CheckableTextView tvSearchResultCommentsHighMarks;//点评高分
    @BindView(R.id.rv_search_item_type)
    RecyclerView rvShops;//底部门店列表

    private Context mContext;
    private boolean isComprehensiveSequencing = true;
    private boolean isSales = false;
    private boolean isDistance = false;

    private boolean isBreaksTheFreight = false;
    private boolean isHighQualityStores = false;
    private boolean isMembersRedEnvelope = false;
    private boolean isCommentsHighMarks = false;


    @Override
    public int getLayoutId() {
        return R.layout.activity_search_result;
    }

    @Override
    public void initView() {
        mContext = this;
        setData();
//        Intent intent = new Intent(this, SearchResultActivity.class);
//        intent.addFlags(FLAG_ACTIVITY_REORDER_TO_FRONT);
//        startActivity(intent);
    }

    public void setData() {
        public_set();

        tvSearchResultBreaksTheFreight.setChecked(isBreaksTheFreight);
        tvSearchResultHighQualityStores.setChecked(isHighQualityStores);
        tvSearchResultMembersRedEnvelope.setChecked(isMembersRedEnvelope);
        tvSearchResultCommentsHighMarks.setChecked(isCommentsHighMarks);


        rvShops.setLayoutManager(new LinearLayoutManager(mContext));
        rvShops.setItemAnimator(new DefaultItemAnimator());

//        rvShops.setAdapter(new SearchShopsAdapter(this, 0));
    }

    private void public_set() {
        tvSearchResultComprehensiveSequencing.setChecked(isComprehensiveSequencing);
        tvSearchResultSales.setChecked(isSales);
        tvSearchResultDistance.setChecked(isDistance);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @OnClick({R.id.iv_search_result_back, R.id.rl_search_type, R.id.tv_home_search, R.id.tv_search_result_comprehensive_sequencing, R.id.tv_search_result_sales, R.id.tv_search_result_distance, R.id.tv_search_result_breaks_the_freight, R.id.tv_search_result_high_quality_stores, R.id.tv_search_result_members_red_envelope, R.id.tv_search_result_comments_high_marks})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_search_result_back:
                finish();
                break;
            case R.id.tv_home_search:
            case R.id.rl_search_type:
                if (Utils.isFastClick()){
                Intent intent = new Intent(this, HomeSearchActivity.class);
                intent.addFlags(FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);}
                break;
            case R.id.tv_search_result_comprehensive_sequencing://综合排序
                if (!isComprehensiveSequencing) {
                    isComprehensiveSequencing = true;
                    isSales = false;
                    isDistance = false;
                    public_set();
                }
                break;
            case R.id.tv_search_result_sales://销量
                if (!isSales) {
                    isComprehensiveSequencing = false;
                    isSales = true;
                    isDistance = false;
                    public_set();
                }
                break;
            case R.id.tv_search_result_distance://距离
                if (!isDistance) {
                    isComprehensiveSequencing = false;
                    isSales = false;
                    isDistance = true;
                    public_set();
                }
                break;

            case R.id.tv_search_result_breaks_the_freight://减免运费
                isBreaksTheFreight = !isBreaksTheFreight;
                tvSearchResultBreaksTheFreight.setChecked(isBreaksTheFreight);

                break;
            case R.id.tv_search_result_high_quality_stores://优质门店
                isHighQualityStores = !isHighQualityStores;
                tvSearchResultHighQualityStores.setChecked(isHighQualityStores);

                break;
            case R.id.tv_search_result_members_red_envelope://会员红包
                isMembersRedEnvelope = !isMembersRedEnvelope;
                tvSearchResultMembersRedEnvelope.setChecked(isMembersRedEnvelope);

                break;
            case R.id.tv_search_result_comments_high_marks://点评高分
                isCommentsHighMarks = !isCommentsHighMarks;
                tvSearchResultCommentsHighMarks.setChecked(isCommentsHighMarks);

                break;

        }
    }

}
